package com.shop.loan.model;

import io.swagger.annotations.ApiModel;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Filter;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.ViewType;
import xyz.erupt.annotation.sub_field.sub_edit.*;
import xyz.erupt.upms.model.base.HyperModel;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name = "s_contract")
@Erupt(
        name = "合同",
        filter = @Filter("Contract.isDelete = false")
)
@SQLDelete(sql = "update r_contract set is_delete = true, delete_time = now() where id = ?")
@ApiModel("合同")
@Getter
@Setter
public class Contract extends HyperModel {

    @EruptField(
            views = @View(title = "合同名称"),
            edit = @Edit(
                    title = "合同名称",
                    notNull = true,
                    search = @Search(vague = true),
                    placeHolder = "请输入合同名称"
            )
    )
    private String name;

    @EruptField(
            views = @View(title = "模版文档", type = ViewType.ATTACHMENT),
            edit = @Edit(title = "模版文档",
                    type = EditType.ATTACHMENT,
                    desc = "请上传docx文档",
                    attachmentType = @AttachmentType(type = AttachmentType.Type.BASE))
    )
    private String detail;

    @EruptField(
            views = @View(title = "空白展示模版", type = ViewType.ATTACHMENT),
            edit = @Edit(title = "空白展示模版",
                    type = EditType.ATTACHMENT,
                    desc = "请上传pdf文档",
                    attachmentType = @AttachmentType(type = AttachmentType.Type.BASE))
    )
    private String detailByEmpty;

    @EruptField(
            views = @View(title = "类型"),
            edit = @Edit(
                    title = "类型",
                    type = EditType.CHOICE,
                    notNull = true,
                    search = @Search,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(label = "其他", value = "0"),
                                    @VL(label = "买卖合同", value = "1"),
                                    @VL(label = "(征信)个人授权书", value = "2"),
                                    @VL(label = "(征信)用户授权协议（授权调用签章）", value = "3"),
                            }
                    ))
    )
    private Integer type;

    @EruptField(
            views = @View(title = "所属类型"),
            edit = @Edit(
                    title = "所属类型",
                    type = EditType.CHOICE,
                    search = @Search,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(label = "直接购买", value = "1"),
                                    @VL(label = "先享后付", value = "2"),
                            }
                    ))
    )
    private Integer packageType;

    @EruptField(
            views = @View(title = "订单页是否显示"),
            edit = @Edit(
                    title = "订单页是否显示",
                    search = @Search,
                    type = EditType.BOOLEAN,
                    notNull = true,
                    boolType = @BoolType(
                            trueText = "显示",
                            falseText = "隐藏"
                    )
            )
    )
    private Boolean appShow = true;


    @EruptField(
            views = @View(title = "是否需要签署"),
            edit = @Edit(
                    title = "是否需要签署",
                    search = @Search,
                    type = EditType.BOOLEAN,
                    notNull = true,
                    boolType = @BoolType(
                            trueText = "需要",
                            falseText = "不需要"
                    )
            )
    )
    private Boolean needSign = true;


    @EruptField(
            views = @View(title = "状态"),
            edit = @Edit(
                    title = "状态",
                    search = @Search,
                    type = EditType.BOOLEAN,
                    notNull = true,
                    boolType = @BoolType(
                            trueText = "正常",
                            falseText = "下线"
                    )
            )
    )
    private Boolean status = true;

    private Boolean isDelete = false;

    private Date deleteTime;

    public Contract() {
    }

    public Contract(Long id) {
        setId(id);
    }
}
